
use std::iter;

use super::{pass::output::OutputPass, rhi::Rhi, RenderPipelineInitInfo};

pub struct RenderPipeline {
    // main_camera_pass: MainCameraPass,
    output_pass: OutputPass,
    rhi: Rhi,
}

impl RenderPipeline {
    pub fn new(init_info: RenderPipelineInitInfo) -> Self {
        // let mut material_layout = Vec::with_capacity(2);
        let rhi = init_info.rhi.clone();

        Self {
            output_pass: OutputPass::new(rhi.clone()),

            rhi,
        }
    }

    pub fn draw(&mut self, view: &wgpu::TextureView, output: Option<&[wgpu::BindGroup]>) {

        if let Some(groups) = output {
            let mut encoder =
                self.rhi
                    .borrow()
                    .device
                    .create_command_encoder(&wgpu::CommandEncoderDescriptor {
                        label: Some("Output Render Encoder"),
                    });

            self.output_pass.draw(&mut encoder, view, groups);
            self.rhi.borrow().queue.submit(iter::once(encoder.finish()));
        }

        // self.main_camera_pass.draw(&mut encoder, view,self.rhi.clone());

        // {
        //     let screen_descriptor = ScreenDescriptor {
        //         physical_width: 1280,
        //         physical_height: 760,
        //         scale_factor: 1.0,
        //     };

        //     self.ui_pass
        //         .add_textures(&self.rhi.borrow().device, &self.rhi.borrow().queue, &self.ui_frame.0)
        //         .expect("add texture ok");
        //     self.ui_pass.update_buffers(&self.rhi.borrow().device, &self.rhi.borrow().queue, &self.ui_frame.1, &screen_descriptor);

        // // Record all render passes.

        //     self.ui_pass.draw(&mut encoder,&view,&self.ui_frame.1,&screen_descriptor,   Some(wgpu::Color::BLACK)).unwrap();
        //     self.ui_pass
        //     .remove_textures(&self.ui_frame.0)
        //     .expect("remove texture ok");
        // }
        // invoke custom pass draw
    }
    // pub fn draw(&self , render_scene:&RenderScene)
}
